package com.maxlen.controller;

import com.maxlen.common.utils.R;
import com.maxlen.entity.service.SeckillService;
import com.maxlen.entity.to.SeckillPriceTO;
import com.maxlen.entity.to.SeckillSessionTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/seckill")
public class SeckillController {

    @Autowired
    private SeckillService seckillService;

    /**
     * 返回当前时间可以参与秒杀商品的信息
     * @return
     */
    @GetMapping("/currentSeckillSkuList")
    public R getCurrentSeckillSkuList(){
        List<SeckillSessionTO.SeckillSkuRelationTO> seckillSessionTOList = seckillService.getCurrentSeckillSkuList();
        return R.ok().setData(seckillSessionTOList);
    }

    /**
     * 根据 skuId 查询是否是秒杀商品，返回离当前时间最近的秒杀信息
     * @param skuId
     * @return
     */
    @GetMapping("/getSkuSeckillInfo/{skuId}")
    public R getSkuSeckillInfo(@PathVariable("skuId") Long skuId){
        List<SeckillSessionTO.SeckillSkuRelationTO> seckillSkuRelationTOList = seckillService.getSkuSeckillInfo(skuId);
        return R.ok().setData(seckillSkuRelationTOList);
    }

    /**
     * 远程调用：根据 skuId 查询是否是秒杀商品，返回离当前时间最近的秒杀信息
     * @param skuIds
     * @return
     */
    @PostMapping("/getSkuSeckillBySkuIdList")
    public R getSkuSeckillBySkuIdList(@RequestBody List<Long> skuIds) {
        List<SeckillPriceTO> seckillPriceTOS = seckillService.getSkuSeckillBySkuIdList(skuIds);
        return R.ok().setData(seckillPriceTOS);
    }


}
